package com.itheima.wemedia.controller.v1;
import com.heima.model.common.constants.mededia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmMaterialDTO;
import com.itheima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Api(value = "素材管理API",tags = "素材管理API")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService materialService;
    @ApiOperation("上传素材")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return materialService.uploadPicture(multipartFile);
    }
    @ApiOperation("列表查询")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDTO wmMaterialDTO){
       return  materialService.findList(wmMaterialDTO);

    }
    @ApiOperation("素材删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id){
        return materialService.delete(id);
    }
    @ApiOperation("收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return materialService.collectOrCancle(id, WemediaConstants.COLLECT_MATERIAL);

    }
    @ApiOperation("取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelcollect(@PathVariable("id") Integer id){
        return materialService.collectOrCancle(id,WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}